<?php 
/**
 * 
 * @author jigal
 *
 */
class EventManager_Form_Decorator_Time extends Zend_Form_Decorator_Abstract
{
    protected $hours = array('00','01','02','04','03','04','05','06','07','08','09','10','11','12','13',
                             '14','15','16','17','18','19','20','21','22','23');
	protected $minutes = array();
	protected $seconds = array();
	
    public function render($content)
    {
    	for($i=0; $i<60; $i++){
    		array_push($this->minutes,sprintf("%02d",$i));
    		array_push($this->seconds,sprintf("%02d",$i));
    	}
    	
    	$element = $this->getElement();
        if (!$element instanceof EventManager_Form_Element_Time) {
            // only want to render Date elements
            return $content;
        }
        

        $view = $element->getView();
        if (!$view instanceof Zend_View_Interface) {
            // using view helpers, so do nothing if no view present
            return $content;
        }

        $hour   = $element->getHours();
        $minute = $element->getMinutes();
        $second = $element->getSeconds();
        $name  = $element->getFullyQualifiedName();

        $params = array(
            'size'      => 1,
            'maxlength' => 2,
        );
        $yearParams = array(
            'size'      => 4,
            'maxlength' => 4,
        );

        $markup = $view->formSelect($name . '[hour]', $hour, $params,$this->hours)
                . '  ' . $view->formSelect($name . '[minute]', $minute, $params,$this->minutes)
                . '  ' . $view->formSelect($name . '[second]', $second, $params,$this->seconds);

        switch ($this->getPlacement()) {
            case self::PREPEND:
                return $markup . $this->getSeparator() . $content;
            case self::APPEND:
            default:
                return $content . $this->getSeparator() . $markup;
        }
    }
}